package com.example.jl.bethinner.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.example.jl.bethinner.R;
import com.example.jl.bethinner.base.BaseActivity;

import java.text.SimpleDateFormat;
import java.util.Date;

public class GetDaysBeforeNowActivity extends BaseActivity {

    private TextView timeBeforeNow;
    private Long time= 1447402100000l;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_days_before_now);
        timeBeforeNow = (TextView)findViewById(R.id.time_before_now);
        timeBeforeNow.setText(getDaysBeforeNow(new Date(time)));
    }


    public static String getDaysBeforeNow(Date date) {
        long sysTime = Long.parseLong(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
        long ymdhms = Long.parseLong(new SimpleDateFormat("yyyyMMddHHmmss").format(date));
        String strYear = "年前";
        String strMonth = "月前";
        String strDay = "天前";
        String strHour = "小时前";
        String strMinute = "分钟前";
        try {
            if (ymdhms == 0) {
                return "";
            }
            long between = (sysTime / 10000000000L) - (ymdhms / 10000000000L);
            if (between > 0) {
                return between + strYear;
            }
            between = (sysTime / 100000000L) - (ymdhms / 100000000L);
            if (between > 0) {
                return between + strMonth;
            }
            between = (sysTime / 1000000L) - (ymdhms / 1000000L);
            if (between > 0) {
                return between + strDay;
            }
            between = (sysTime / 10000) - (ymdhms / 10000);
            if (between > 0) {
                return between + strHour;
            }
            between = (sysTime / 100) - (ymdhms / 100);
            if (between > 0) {
                return between + strMinute;
            }
            return "1" + strMinute;
        } catch (Exception e) {
            return "";
        }
    }

}
